home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / WindowsBorderFactory.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  168 lines

  1. /*
  2.  * @(#)WindowsBorderFactory.java    1.4 98/04/09
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.windows;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.border.*;
  25. import com.sun.java.swing.plaf.*;
  26. import com.sun.java.swing.plaf.basic.*;
  27.  
  28. import java.awt.Component;
  29. import java.awt.Insets;
  30. import java.awt.Dimension;
  31. import java.awt.Color;
  32. import java.awt.Graphics;
  33. import java.io.Serializable;
  34.  
  35.  
  36. /**
  37.  * Factory object that can vend Borders appropriate for the Windows 95 L & F.
  38.  * @version 1.4 04/09/98
  39.  * @author Rich Schiavi
  40.  */
  41.  
  42. public class WindowsBorderFactory
  43. {
  44.  
  45.   private static Border buttonBorder;
  46.   private static Border toggleButtonBorder;
  47.   private static Border radioButtonBorder;
  48.   
  49.   public static Border getButtonBorder() {
  50.     if (buttonBorder == null) {
  51.       buttonBorder = new WindowsButtonBorder();
  52.     }
  53.     return buttonBorder;
  54.   }
  55.  
  56.   public static Border getToggleButtonBorder() {
  57.     if (toggleButtonBorder == null) {
  58.       toggleButtonBorder = new WindowsToggleBorder();
  59.     }
  60.     return toggleButtonBorder;
  61.   }
  62.  
  63.   public static Border getRadioButtonBorder() {
  64.     if (radioButtonBorder == null) {
  65.       radioButtonBorder = new WindowsRadioBorder();
  66.     }
  67.     return radioButtonBorder;
  68.   }
  69.  
  70.   public static Border getProgressBarBorder() {
  71.     return new WindowsProgressBarBorder();
  72.   }
  73.  
  74.   private static class WindowsToggleBorder extends AbstractBorder {
  75.  
  76.         public void paintBorder(Component c, Graphics g, int x, int y, 
  77.                                 int width, int height) {
  78.             if (c instanceof AbstractButton) {
  79.                 AbstractButton b = (AbstractButton)c;
  80.                 ButtonModel model = b.getModel();
  81.  
  82.                 if (model.isArmed() && model.isPressed() || model.isSelected()) {
  83.                     BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height);
  84.                 } else {
  85.                     BasicGraphicsUtils.drawBezel(g, x, y, width, height, 
  86.                                          false, b.isFocusPainted() && b.hasFocus());
  87.                 }
  88.             } else {    
  89.                 BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false);
  90.             }
  91.         }
  92.  
  93.         public Insets getBorderInsets(Component c)       {
  94.             return new Insets(2, 2, 2, 2);
  95.         }
  96.     }
  97.  
  98.  
  99.   private static class WindowsButtonBorder extends AbstractBorder {
  100.     public void paintBorder(Component c, Graphics g, int x, int y, 
  101.                             int width, int height) {
  102.       boolean isPressed = false;
  103.       boolean isDefault = false;
  104.       
  105.       if (c instanceof AbstractButton) {
  106.     AbstractButton b = (AbstractButton)c;
  107.     ButtonModel model = b.getModel();
  108.     
  109.     isPressed = model.isPressed() && model.isArmed();
  110. /*
  111.     hasFocus = (model.isArmed() && isPressed) || 
  112.       (b.isFocusPainted() && b.hasFocus());
  113.           */
  114.         isDefault = (b instanceof JButton && ((JButton)b).isDefaultButton());
  115.       }    
  116.       BasicGraphicsUtils.drawBezel(g, x, y, width, height, 
  117.                    isPressed, isDefault);
  118.     }
  119.     public Insets getBorderInsets(Component c)       {
  120.       return new Insets(2, 2, 2, 2);
  121.     }
  122.   }
  123.  
  124.     private static class WindowsRadioBorder extends AbstractBorder {
  125.  
  126.         public void paintBorder(Component c, Graphics g, int x, int y, 
  127.                                 int width, int height) {
  128.  
  129.             if (c instanceof AbstractButton) {
  130.                 AbstractButton b = (AbstractButton)c;
  131.                 ButtonModel model = b.getModel();
  132.  
  133.                 if (model.isArmed() && model.isPressed() || model.isSelected()) {
  134.                     BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height);
  135.                 } else {
  136.                     BasicGraphicsUtils.drawBezel(g, x, y, width, height, 
  137.                                          false, b.isFocusPainted() && b.hasFocus());
  138.                 }
  139.             } else {    
  140.                 BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false);
  141.             }
  142.         }
  143.  
  144.         public Insets getBorderInsets(Component c)       {
  145.             return new Insets(2, 2, 2, 2);
  146.         }
  147.     }
  148.  
  149.   private static class WindowsProgressBarBorder extends AbstractBorder {
  150.  
  151.         public void paintBorder(Component c, Graphics g, int x, int y, 
  152.                                 int width, int height) {
  153.         g.setColor(Color.gray);
  154.         g.drawLine(x,y, width-1,y); // draw top
  155.         g.drawLine(x,y, x,height-1); // draw left
  156.         g.setColor(Color.white);
  157.         g.drawLine(x,height-1, width-1,height-1); // draw bottom
  158.         g.drawLine(width-1,y, width-1,height-1); // draw right
  159.         }
  160.  
  161.         public Insets getBorderInsets(Component c)       {
  162.             return new Insets(1,1,1,1);
  163.         }
  164.     }
  165.  
  166.  
  167. }
  168.